#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e5 + 10, M = 1e5 + 10;

int n;
string a;

char offset = 'a';
int tr[M][26], fail[M], idx;
int ed[N];

char ans[N];
int st[N], t1, t2;

void insert(const string& s)
{
    int p = 0;
    for (char it : s) {
        int c = it - offset;
        if (tr[p][c] == 0) tr[p][c] = ++idx;
        p = tr[p][c];
    }
    ed[p] = s.length();
}

void setfail()
{
    queue<int> q;
    for (int i = 0;i < 26;i++) if (tr[0][i]) { q.push(tr[0][i]); }
    while (!q.empty()) {
        int now = q.front();q.pop();
        for (int i = 0;i < 26;i++) {
            if (tr[now][i]) {
                fail[tr[now][i]] = tr[fail[now]][i];
                q.push(tr[now][i]);
            } else tr[now][i] = tr[fail[now]][i];
        }
    }
}

void solve()
{
    cin >> a >> n;
    for (int i = 0;i < n;i++) {
        string c;cin >> c;
        insert(c);
    }
    setfail();

    int p = 0;
    st[++t1] = p;
    for (char it : a) {
        int c = it - offset;
        p = tr[p][c];
        st[++t1] = p, ans[++t2] = it;

        int len = ed[p];
        t1 -= len, t2 -= len;

        p = st[t1];
    }

    for (int i = 1;i <= t2;i++) cout << ans[i];
}


signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}